package com.lanou.service.impl;

import com.alibaba.fastjson.JSON;
import com.lanou.service.CatService;
import com.lanou.utils.HttpClientUtils;
import com.lanou.utils.ShiHuiResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by QuChao on 2018/12/7
 */
@Service
public class CatServiceImpl implements CatService {
    @Value("${CAT_SHOW_CAT_URL}")
    private String CAT_SHOW_CAT_URL;

    @Override
    public Map<String, Object> showAllCat() {
        String raw = HttpClientUtils.getRaw(CAT_SHOW_CAT_URL);
        Map map = JSON.parseObject(raw, Map.class);
        List data = (List) map.get("data");
        if (!data.isEmpty()) {
            return ShiHuiResult.ok(data);
        } else {
            return ShiHuiResult.error(400);
        }
    }
}
